<!-- 款项结清 -->
<template>
  <el-dialog
    width="900px"
    class="increase-record-dialog"
    :append-to-body="true"
    top="6vh"
    title="款项结清"
    :visible="$store.state.dialog.paySettlement"
    @close="close">
    <el-row>
      <el-col :span="24">
        <el-form :model="order" label-width="100px" size="mini">
          <el-row>
            <el-form-item label="客户/用箱人">
              <el-input disabled="disabled" v-model="order.CompanyName"></el-input>
            </el-form-item>
            <el-form-item label="打款金额">
              <el-input disabled="disabled" v-model="formMoney"></el-input>
            </el-form-item>
          </el-row>
          <!-- <el-row>
            <el-form-item label="备注">
              <el-input type="textarea" v-model="remark"></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="相关图像">
              <div class="uploader">
                <el-upload
                  action="http://fx.api.ypt56.net/api/image"
                  :show-file-list="true"
                  :data="uploadData"
                  :multiple="false"
                  name="Picture"
                  v-model="image"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="image" :src="image" class="avatar">
                  <i v-if="!image" class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </div>
            </el-form-item>
          </el-row> -->
        </el-form>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" v-if="loadShow" @click="paySettlement()" size="mini">确 定</el-button>
      <el-button type="primary" size="mini" v-else :loading="true">加载中</el-button>
      <el-button @click="close()" size="mini">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  paySettlement,
  settleMoney
} from '../api/finance'
export default {
  data () {
    return {
      // image: '',
      // remark: ''
      formMoney: '',
      loadShow: true
    }
  },
  props: {
    order: {
      type: Object,
      default: () => {
        return {}
      }
    }
    // uploadData: {
    //   type: Object,
    //   default: () => {
    //     return {}
    //   }
    // }
  },
  watch: {
    '$store.state.dialog.paySettlement' (value) {
      if (value) {
        this.getSettlement()
      }
    }
  },
  methods: {
    close () {
      this.$store.commit('hide_paysettlement_dialog')
    },
    // 款项结清
    async paySettlement () {
      if (Number(this.formMoney) < 0 || Number(this.formMoney) === 0 || Number(this.formMoney) === '') {
        this.$notify({
          title: '警告',
          message: '打款金额不能小于或等于0！',
          type: 'warning'
        })
        return false
      }
      this.loadShow = false
      let that = this
      const res = await paySettlement({
        customerId: this.order.customerId, // 客户编号
        money: this.formMoney // 金额
      })
      if (res.status === 200) {
        this.$notify({
          title: '成功',
          message: res.msg,
          type: 'success'
        })
        this.remark = ''
        setTimeout(function () {
          that.loadShow = true
        }, 500)
        this.$parent.getTlementList(1, 15)
        this.close()
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
        this.loadShow = true
      }
    },
    // 获取结清金额
    async getSettlement () {
      const res = await settleMoney({
        customerId: this.order.customerId, // 客户编号
        money: this.order.wjqMoney // 金额
      })
      if (res.status === 200) {
        if (res.data.length !== 0) {
          this.formMoney = res.data[0].totalMoney
        } else {
          this.formMoney = ''
        }
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    }
    // beforeAvatarUpload (file) {
    //   this.uploadData.image = file.name.split('.')[0]
    // },
    // handleAvatarSuccess (res, file) {
    //   this.image = res.data[0].path
    // }
  }
}
</script>

<style scoped lang="less">
.increase-record-dialog {
  .uploader {
    width: 178px;
    height: 178px;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .uploader:hover {
    border-color: #409EFF;
  }
  .uploader /deep/ .el-upload__input{
    display: none;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
